@extends('app')

@section('content')
    <div class="layui-card" style="height:100vh;">
        <div class="layui-fluid">
            <div class="layui-row layui-col-space15">
                <div class="layui-col-md12">
                    @component('form.form',['id'=>'form'])

                        @include('form.input',[
                               'label' => '标题',
                               'name'  => 'title',
                               'class' => 'layui-col-md12',
                               'val'   => $model->title??''
                           ])

                        <div class="layui-form-item layui-form-text" >
                            <div style="/*border:1px solid #D2D2D2;*/text-align: center;">


                                <div alt="" class="upload" id="image_add" >
                                    <div id="img_url" style="@if(!isset($model->img_url)) display: none;@endif">
                                        <input type="hidden" name="img_url" >
                                        <img src="{{ $model->img_url??'' }}" style=" max-height: 165px;max-width: 100%;"/>
                                    </div>
                                    <div class="update-none" style="@if(isset($model->img_url)) display: none;@endif">
                                        <i class="iconfont icon-shangchuantupian1"></i>
                                        <p>点击添加图片</p>
                                    </div>
                                </div>
                                <div style="clear: both"></div>
                            </div>
                        </div>

                        @include('form.input',[
                               'label' => '跳转连接',
                               'name'  => 'links',
                               'must'  => false,
                               'class' => 'layui-col-md12',
                               'val'   => $model->links??''
                           ])

                        @include('form.input',[
                               'label' => '排序',
                               'name'  => 'sort',
                               'must'  => false,
                               'class' => 'layui-col-md12',
                               'val'   => $model->sort??'99'
                           ])

                        @include('form.submit',['label'=>'立即提交','form'=>'form'])
                    @endcomponent
                </div>
            </div>
        </div>
    </div>
@endsection

@section('js')
<script>
    layui.use('upload', function(){
        var upload = layui.upload;
        var $ = layui.$;

        //执行实例
        var uploadInst = upload.render({
            elem: '#image_add' //绑定元素
            ,url: '/upload/image' //上传接口
            ,done: function(res){
                console.info(res.data.src);
                //上传完毕回调
                $('#img_url img').attr('src',res.data.src);
                $('#img_url input[name=img_url]').val(res.data.src);
                $('#img_url').show();
                $('#image_add .update-none').hide();
            }
            ,error: function(){
                //请求异常回调
            }
        });
    });
</script>
@endsection